package com.xiongjie.msg;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;

/**
 * 从主Verticle部署其他的Verticle
 * 部署方式有两种：1.verticle的对象；2.verticle的类名
 * 同一个httpserver可以部署多次，通过轮询的方式
 */
public class MainVertx extends AbstractVerticle {

    @Override
    public void start(Future<Void> f) throws Exception {
        Future<String> future=Future.future();
        vertx.deployVerticle(MessageDriverConsumerVerticle::new,new DeploymentOptions(),future.completer());

        future.compose(id -> {
            Future<String> httpFuture = Future.future();
            vertx.deployVerticle(MessageDriverProducerVerticle.class.getName(), new DeploymentOptions().setInstances(2), httpFuture.completer());
            return httpFuture;
        }).setHandler(ar -> {
            if (ar.succeeded()) {
                f.complete();
            } else {
                f.fail(ar.cause());
            }
        });
    }
}
